<?php
namespace Admin\Controller;

use Think\Controller;

class FuController extends Controller
{

    public function index()
    {
        sess();
        $cust = M('Fu');
        $map = _search('Fu');
        $map['uid'] = session('uid');
        $count = $cust->where($map)->count();
        $Page = getpage($count, 3); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $cust->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function outxls()
    {
        sess();
        $model = M('Fu');
        $map = _search("Fu");
        $map['uid'] = session('uid');
        $list = $model->where($map)
            ->field('id,jhname,bianhao,type,jine,juname,beizhu,uname,addtime')
            ->select();
        $headArr = array(
            'ID',
            '关联合同',
            '单据编号',
            '付款方式',
            '付款金额',
            '经办人',
            '备注',
            '添加人',
            '添加时间'
        );
        $filename = '付款记录';
        xlsout($filename, $headArr, $list);
        updateTime();
    }

    public function add()
    {
        sess();
        if (IS_POST) {
            if (add("Hetong")) {
                $this->success('新增成功', U('Fu/index'));
            } else {
                $this->error('新增失败');
            }
        }
        updateTime();
        $this->display();
    }

    public function edit()
    {
        sess();
        $model = M('Fu');
        $Rs = $model->getById(I('get.id'));
        $this->assign('Rs', $Rs);
        if (IS_POST) {
            if (edit("Fu")) {
                $this->success('修改成功', U('Fu/index'));
            } else {
                $this->error('修改失败');
            }
        }
        updateTime();
        $this->display();
    }

    public function del()
    {
        sess();
        if (del("Fu")) {
            redirect(U('Fu/index'));
        } else {
            $this->error('删除失败');
        }
        updateTime();
    }

    public function view()
    {
        sess();
        $model = M('Fu');
        $Rs = $model->getByid(I('get.id'));
        $this->assign('Rs', $Rs);
        updateTime();
        $this->display();
    }
}